package com.gvjn.ant.customtasks.commons;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;

public class RandomUniqueStrings {

//	public static void main(String[] args) {
//		List<String> randomStrings = generate(10000);
//
//		for (int i=0; i<randomStrings.size(); i++) {
//			System.out.println((i+1) + " ### " + randomStrings.get(i));
//		}
//	}

	public static List<String> generate(int count, String prependTxt) {
		List<String> randomStrings = new ArrayList<String>();

		//while(randomStrings.size() != count){
			randomStrings = randomizer(randomStrings,count);
			randomStrings = checkDuplicates(randomStrings);
		//}

		for (int i=0; i<randomStrings.size(); i++) {
			randomStrings.set(i,prependTxt + randomStrings.get(i));
		}

		return randomStrings;
	}

	private static List randomizer(List<String> randomStrings, int size){
		for (int i=0; i<size; i++) {
			Random random = new Random();
			long r1 = random.nextLong();
			long r2 = random.nextLong();
			String hash1 = Long.toHexString(r1);
			String hash2 = Long.toHexString(r2);
			String hash = hash1 + hash2;

			randomStrings.add(hash);
		}

		return randomStrings;
	}

	public static List checkDuplicates(List<String> randomStrings){
		HashSet<String> hashSet = new HashSet(randomStrings);
		randomStrings.clear();
		randomStrings.addAll(hashSet);

		return randomStrings;
	}
}